package ducna.misscall.screen.misscall.adapter;

import java.util.ArrayList;

import android.app.Activity;
import android.content.Context;
import android.view.LayoutInflater;
import android.view.View;
import android.view.ViewGroup;
import android.widget.BaseAdapter;
import android.widget.TextView;
import ducna.alozo.misscall.R;
import ducna.misscall.common.model.ContactMiss;
import ducna.misscall.common.view.CircleImageView;

public class ListMissCallAdapter extends BaseAdapter {
	private Context mContext;
	private ArrayList<ContactMiss> mListContactMiss;

	public ListMissCallAdapter(Context context) {
		this.mContext = context;
		mListContactMiss = new ArrayList<ContactMiss>();
	}
	
	
	public void setListContactMiss(ArrayList<ContactMiss> mListContactMiss) {
		if (mListContactMiss != null) {
			this.mListContactMiss = mListContactMiss;
			notifyDataSetChanged();
		}
		
	}


	@Override
	public int getCount() {
		return mListContactMiss.size();
	}

	@Override
	public Object getItem(int positon) {
		return mListContactMiss.get(positon);
	}

	@Override
	public long getItemId(int position) {
		return position;
	}

	@Override
	public View getView(int position, View convertView, ViewGroup parent) {
		View row = convertView;
		final ViewHolder holder;
		if (row == null) {
			LayoutInflater mInflater = (LayoutInflater) mContext
					.getSystemService(Activity.LAYOUT_INFLATER_SERVICE);
			row = mInflater.inflate(R.layout.item_list_miss_call, null);
			holder = new ViewHolder();
			holder.circleImageView = (CircleImageView) row.findViewById(R.id.circleImageView);
			holder.textViewNumberMissCall = (TextView) row.findViewById(R.id.textViewNumberMissCall);
			holder.textViewName = (TextView) row.findViewById(R.id.textViewName);
			holder.textViewLastDate = (TextView) row.findViewById(R.id.textViewLastDate);
			holder.textViewLastTime = (TextView) row.findViewById(R.id.textViewLastTime);
			holder.textViewCallBack = (TextView) row.findViewById(R.id.textViewCallBack);
			holder.textViewMessage = (TextView) row.findViewById(R.id.textViewMessage);
			row.setTag(holder);
		} else {
			holder = (ViewHolder) row.getTag();
		}
		
		ContactMiss contactMiss = mListContactMiss.get(position);
		holder.circleImageView.setImageResource(R.drawable.ic_launcher);
		String numberCall = String.format(mContext.getString(R.string.number_miss_call), contactMiss.getNumberMiss());
		holder.textViewNumberMissCall.setText(numberCall);
		holder.textViewName.setText(contactMiss.getName());
		holder.textViewLastDate.setText(contactMiss.getLastDate());
		holder.textViewLastTime.setText(contactMiss.getLastTime());
		return row;
	}
	
	static class ViewHolder {
		CircleImageView circleImageView;
		TextView textViewName;
		TextView textViewNumberMissCall;
		TextView textViewLastDate;
		TextView textViewLastTime;
		TextView textViewCallBack;
		TextView textViewMessage;
		
	}

}
